/*
ID: icerupt1
PROG: sort3
LANG: C++11
*/
#include <fstream>
#include <iostream>

int const maxn = 1024;
int da[maxn];
int count[3];
int divide[3][3];
int n;

int main()
{
	std::ifstream fin {"sort3.in" };
	std::ofstream fout{"sort3.out"};

	fin >> n;
	for (int i = 0; i < n; i++) {
		fin >> da[i];
		count[--da[i]]++;
	}

	for (int i = 0, j = 0, len = count[0]; i < n; i++) {
		while (i >= len) len += count[++j];
		divide[j][da[i]]++;
	}

	int ans = 0, tmp;
	for (int i = 1; i <= 2; i++) {
		tmp = std::min(divide[0][1], divide[i][0]);
		ans += tmp;
		divide[0][1] -= tmp;  divide[i][0] -= tmp;
		if (i != 1) divide[i][1] += tmp;
	}

	for (int i = 2; i >= 1; i--) {
		tmp = std::min(divide[0][2], divide[i][0]);
		ans += tmp;
		divide[0][2] -= tmp;  divide[i][0] -= tmp;
		if (i != 2) divide[i][2] += tmp;
	}

	ans += divide[1][2];

	std::cout << ans << '\n';
	fout << ans << '\n';
}
